/************************************************************************
* Template class, store graphics resources. 
* Author : Shaolan
* Version : 1.0
* Website : http://shaolan.net
*/
#include "template.hpp"

// DEBUG FUNCTION
void printT(const char * s) {
	pspDebugScreenSetXY(0,0);
	pspDebugScreenPrintf(s);
}

// ***********************************************************************************************************************************
// Static method which return a default template
Template * Template::DEFAULT(){
	Template * t = new Template();
	t->setBackground(new Background("Data/Level/background.png"));
	t->setResource(GRID,"Data/Level/grid.png");
	t->setResource(BLUE,"Data/Level/blue.png");
	t->setResource(GREEN,"Data/Level/green.png");
	t->setResource(RED,"Data/Level/red.png");
	return t;
}

// ***********************************************************************************************************************************
// Public Constructor
Template::Template(){
	// Allocation du tableau de ge_Image
	resource = new ge_Image*[END];
	setBackground(NULL);
}

// ***********************************************************************************************************************************
// Public Destructor
Template::~Template(){
	for (int i = 0; i < END ; i++){
		geFree(resource[i]);
	}
	delete * resource;
}

// ***********************************************************************************************************************************
// Getters
ge_Image * Template::getResource(int i) const { return resource[i]; }
Background * Template::getBackground() const { return background; }

// ***********************************************************************************************************************************
// Setters
void Template::setResource(int i,ge_Image* p) { resource[i] = p; }
void Template::setResource(int i,std::string p) { resource[i] = geLoadImage(p.c_str()); geSwizzle(resource[i]); }
void Template::setBackground(Background * b) { background = b; }

// ***********************************************************************************************************************************
// Draw method
void Template::draw(){
	printT("::Template::draw() call");
	background->draw();
	geDrawImage(40,26,resource[GRID]);
}
